$(document).ready(function(){
	$("#jqwCloseBtn").on("click", function(){
		var jqw = new jqWindow();
		jqw.destroyJqwSelected();
	});
	
	$("#jqwFormSendEmailBtn").on("click", function(){
		if(!validationForm()) return;
		
		var options = new Object();
		options["url"] = "/template/system/userInfo/_sendMailFormSend";
		jqwSave(options);
	});
});

function validationForm(){
	var def = new validDefinition();
	var validator = new formValidator("frmSendEmail", def.rules, def.messages);
	return validator.validation();
}

function jqwSave(opts){
	$("#usrGroupLst option").each(function(){
		if($(this).is(":disabled")) $(this).attr("disabled", false);
		$(this).attr("selected", true);
	});
	
	var data = new FormData();
	data.append("to", $("input[name='to']").val());
	data.append("subject", $("input[name='subject']").val());
	data.append("text", $("textarea[name='content']").val());
	
	var files = $("input[name='file']");
    $.each($(files), function(i, tag) {
        $.each($(tag)[0].files, function(i, file) {
        	data.append(tag.name, file);
        });
    });

	var options = new Object();
	options["url"] = opts["url"];
	options["type"] = "POST";
	options["dataType"] = "json";
	options["data"] = data;
	
	var jqw = new jqWindow();
	jqw.jqwSet(options);
	jqw.fileLoadJqWindow();
}